package com.amado.course34Thread;

import java.util.concurrent.*;
import java.util.logging.Logger;

public class S13ThreadPoolExecutorExceptionHandler {
    static Logger logger = Logger.getLogger("a");

    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(
                2,
                5,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardPolicy() {
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        System.out.println(this.getClass().getName() + "\r\n--- 队列已满，请稍后再来");
                    }
                }) {
            @Override
            protected void afterExecute(Runnable r, Throwable t) {
                super.afterExecute(r, t);
                if (t != null) {
                    System.out.println("error" + t.getMessage());
                }
            }
        };
        pool.execute(() -> {
            System.out.println(1);
        });
        pool.execute(() -> {
            System.out.println(1 / 0);
        });
        pool.shutdown();
    }

}
